package torque.generated;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;





/**
 * Table Player
 *
 * This class was autogenerated by Torque on:
 *
 * [Wed Mar 21 13:44:28 CET 2012]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Player
 */
public abstract class BasePlayer extends BaseObject
{
    /** Serial version */
    private static final long serialVersionUID = 1332333868768L;

    /** The Peer class */
    private static final PlayerPeer peer =
        new PlayerPeer();


    /** The value for the playerId field */
    private int playerId;

    /** The value for the nom field */
    private String nom;

    /** The value for the vaisseauId field */
    private int vaisseauId;

    /** The value for the pointdaction field */
    private int pointdaction;

    /** The value for the pointdevie field */
    private int pointdevie;


    /**
     * Get the PlayerId
     *
     * @return int
     */
    public int getPlayerId()
    {
        return playerId;
    }


    /**
     * Set the value of PlayerId
     *
     * @param v new value
     */
    public void setPlayerId(int v) throws TorqueException
    {

        if (this.playerId != v)
        {
            this.playerId = v;
            setModified(true);
        }



        // update associated Partie
        if (collPartiesRelatedByIdplayer1 != null)
        {
            for (int i = 0; i < collPartiesRelatedByIdplayer1.size(); i++)
            {
                ((Partie) collPartiesRelatedByIdplayer1.get(i))
                        .setIdplayer1(v);
            }
        }

        // update associated Partie
        if (collPartiesRelatedByIdplayer2 != null)
        {
            for (int i = 0; i < collPartiesRelatedByIdplayer2.size(); i++)
            {
                ((Partie) collPartiesRelatedByIdplayer2.get(i))
                        .setIdplayer2(v);
            }
        }
    }

    /**
     * Get the Nom
     *
     * @return String
     */
    public String getNom()
    {
        return nom;
    }


    /**
     * Set the value of Nom
     *
     * @param v new value
     */
    public void setNom(String v) 
    {

        if (!ObjectUtils.equals(this.nom, v))
        {
            this.nom = v;
            setModified(true);
        }


    }

    /**
     * Get the VaisseauId
     *
     * @return int
     */
    public int getVaisseauId()
    {
        return vaisseauId;
    }


    /**
     * Set the value of VaisseauId
     *
     * @param v new value
     */
    public void setVaisseauId(int v) throws TorqueException
    {

        if (this.vaisseauId != v)
        {
            this.vaisseauId = v;
            setModified(true);
        }


        if (aVaisseau != null && !(aVaisseau.getVaisseauId() == v))
        {
            aVaisseau = null;
        }

    }

    /**
     * Get the Pointdaction
     *
     * @return int
     */
    public int getPointdaction()
    {
        return pointdaction;
    }


    /**
     * Set the value of Pointdaction
     *
     * @param v new value
     */
    public void setPointdaction(int v) 
    {

        if (this.pointdaction != v)
        {
            this.pointdaction = v;
            setModified(true);
        }


    }

    /**
     * Get the Pointdevie
     *
     * @return int
     */
    public int getPointdevie()
    {
        return pointdevie;
    }


    /**
     * Set the value of Pointdevie
     *
     * @param v new value
     */
    public void setPointdevie(int v) 
    {

        if (this.pointdevie != v)
        {
            this.pointdevie = v;
            setModified(true);
        }


    }

    



    private Vaisseau aVaisseau;

    /**
     * Declares an association between this object and a Vaisseau object
     *
     * @param v Vaisseau
     * @throws TorqueException
     */
    public void setVaisseau(Vaisseau v) throws TorqueException
    {
        if (v == null)
        {
            setVaisseauId( 0);
        }
        else
        {
            setVaisseauId(v.getVaisseauId());
        }
        aVaisseau = v;
    }


    /**
     * Returns the associated Vaisseau object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Vaisseau object
     * @throws TorqueException
     */
    public Vaisseau getVaisseau()
        throws TorqueException
    {
        if (aVaisseau == null && (this.vaisseauId != 0))
        {
            aVaisseau = VaisseauPeer.retrieveByPK(SimpleKey.keyFor(this.vaisseauId));
        }
        return aVaisseau;
    }

    /**
     * Return the associated Vaisseau object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Vaisseau object
     * @throws TorqueException
     */
    public Vaisseau getVaisseau(Connection connection)
        throws TorqueException
    {
        if (aVaisseau == null && (this.vaisseauId != 0))
        {
            aVaisseau = VaisseauPeer.retrieveByPK(SimpleKey.keyFor(this.vaisseauId), connection);
        }
        return aVaisseau;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setVaisseauKey(ObjectKey key) throws TorqueException
    {

        setVaisseauId(((NumberKey) key).intValue());
    }
   


    /**
     * Collection to store aggregation of collPartiesRelatedByIdplayer1
     */
    protected List collPartiesRelatedByIdplayer1;

    /**
     * Temporary storage of collPartiesRelatedByIdplayer1 to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initPartiesRelatedByIdplayer1()
    {
        if (collPartiesRelatedByIdplayer1 == null)
        {
            collPartiesRelatedByIdplayer1 = new ArrayList();
        }
    }


    /**
     * Method called to associate a Partie object to this object
     * through the Partie foreign key attribute
     *
     * @param l Partie
     * @throws TorqueException
     */
    public void addPartieRelatedByIdplayer1(Partie l) throws TorqueException
    {
        getPartiesRelatedByIdplayer1().add(l);
        l.setPlayerRelatedByIdplayer1((Player) this);
    }

    /**
     * Method called to associate a Partie object to this object
     * through the Partie foreign key attribute using connection.
     *
     * @param l Partie
     * @throws TorqueException
     */
    public void addPartieRelatedByIdplayer1(Partie l, Connection con) throws TorqueException
    {
        getPartiesRelatedByIdplayer1(con).add(l);
        l.setPlayerRelatedByIdplayer1((Player) this);
    }

    /**
     * The criteria used to select the current contents of collPartiesRelatedByIdplayer1
     */
    private Criteria lastPartiesRelatedByIdplayer1Criteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getPartiesRelatedByIdplayer1(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List getPartiesRelatedByIdplayer1()
        throws TorqueException
    {
        if (collPartiesRelatedByIdplayer1 == null)
        {
            collPartiesRelatedByIdplayer1 = getPartiesRelatedByIdplayer1(new Criteria(10));
        }
        return collPartiesRelatedByIdplayer1;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Player has previously
     * been saved, it will retrieve related PartiesRelatedByIdplayer1 from storage.
     * If this Player is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getPartiesRelatedByIdplayer1(Criteria criteria) throws TorqueException
    {
        if (collPartiesRelatedByIdplayer1 == null)
        {
            if (isNew())
            {
               collPartiesRelatedByIdplayer1 = new ArrayList();
            }
            else
            {
                criteria.add(PartiePeer.IDPLAYER1, getPlayerId() );
                collPartiesRelatedByIdplayer1 = PartiePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.add(PartiePeer.IDPLAYER1, getPlayerId());
                if (!lastPartiesRelatedByIdplayer1Criteria.equals(criteria))
                {
                    collPartiesRelatedByIdplayer1 = PartiePeer.doSelect(criteria);
                }
            }
        }
        lastPartiesRelatedByIdplayer1Criteria = criteria;

        return collPartiesRelatedByIdplayer1;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getPartiesRelatedByIdplayer1(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getPartiesRelatedByIdplayer1(Connection con) throws TorqueException
    {
        if (collPartiesRelatedByIdplayer1 == null)
        {
            collPartiesRelatedByIdplayer1 = getPartiesRelatedByIdplayer1(new Criteria(10), con);
        }
        return collPartiesRelatedByIdplayer1;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Player has previously
     * been saved, it will retrieve related PartiesRelatedByIdplayer1 from storage.
     * If this Player is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getPartiesRelatedByIdplayer1(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collPartiesRelatedByIdplayer1 == null)
        {
            if (isNew())
            {
               collPartiesRelatedByIdplayer1 = new ArrayList();
            }
            else
            {
                 criteria.add(PartiePeer.IDPLAYER1, getPlayerId());
                 collPartiesRelatedByIdplayer1 = PartiePeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                 criteria.add(PartiePeer.IDPLAYER1, getPlayerId());
                 if (!lastPartiesRelatedByIdplayer1Criteria.equals(criteria))
                 {
                     collPartiesRelatedByIdplayer1 = PartiePeer.doSelect(criteria, con);
                 }
             }
         }
         lastPartiesRelatedByIdplayer1Criteria = criteria;

         return collPartiesRelatedByIdplayer1;
     }



















    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Player is new, it will return
     * an empty collection; or if this Player has previously
     * been saved, it will retrieve related PartiesRelatedByIdplayer1 from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Player.
     */
    protected List getPartiesRelatedByIdplayer1JoinPlayerRelatedByIdplayer2(Criteria criteria)
        throws TorqueException
    {
        if (collPartiesRelatedByIdplayer1 == null)
        {
            if (isNew())
            {
               collPartiesRelatedByIdplayer1 = new ArrayList();
            }
            else
            {
                criteria.add(PartiePeer.IDPLAYER1, getPlayerId());
                collPartiesRelatedByIdplayer1 = PartiePeer.doSelectJoinPlayerRelatedByIdplayer2(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(PartiePeer.IDPLAYER1, getPlayerId());
            if (!lastPartiesRelatedByIdplayer1Criteria.equals(criteria))
            {
                collPartiesRelatedByIdplayer1 = PartiePeer.doSelectJoinPlayerRelatedByIdplayer2(criteria);
            }
        }
        lastPartiesRelatedByIdplayer1Criteria = criteria;

        return collPartiesRelatedByIdplayer1;
    }





    /**
     * Collection to store aggregation of collPartiesRelatedByIdplayer2
     */
    protected List collPartiesRelatedByIdplayer2;

    /**
     * Temporary storage of collPartiesRelatedByIdplayer2 to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initPartiesRelatedByIdplayer2()
    {
        if (collPartiesRelatedByIdplayer2 == null)
        {
            collPartiesRelatedByIdplayer2 = new ArrayList();
        }
    }


    /**
     * Method called to associate a Partie object to this object
     * through the Partie foreign key attribute
     *
     * @param l Partie
     * @throws TorqueException
     */
    public void addPartieRelatedByIdplayer2(Partie l) throws TorqueException
    {
        getPartiesRelatedByIdplayer2().add(l);
        l.setPlayerRelatedByIdplayer2((Player) this);
    }

    /**
     * Method called to associate a Partie object to this object
     * through the Partie foreign key attribute using connection.
     *
     * @param l Partie
     * @throws TorqueException
     */
    public void addPartieRelatedByIdplayer2(Partie l, Connection con) throws TorqueException
    {
        getPartiesRelatedByIdplayer2(con).add(l);
        l.setPlayerRelatedByIdplayer2((Player) this);
    }

    /**
     * The criteria used to select the current contents of collPartiesRelatedByIdplayer2
     */
    private Criteria lastPartiesRelatedByIdplayer2Criteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getPartiesRelatedByIdplayer2(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List getPartiesRelatedByIdplayer2()
        throws TorqueException
    {
        if (collPartiesRelatedByIdplayer2 == null)
        {
            collPartiesRelatedByIdplayer2 = getPartiesRelatedByIdplayer2(new Criteria(10));
        }
        return collPartiesRelatedByIdplayer2;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Player has previously
     * been saved, it will retrieve related PartiesRelatedByIdplayer2 from storage.
     * If this Player is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getPartiesRelatedByIdplayer2(Criteria criteria) throws TorqueException
    {
        if (collPartiesRelatedByIdplayer2 == null)
        {
            if (isNew())
            {
               collPartiesRelatedByIdplayer2 = new ArrayList();
            }
            else
            {
                criteria.add(PartiePeer.IDPLAYER2, getPlayerId() );
                collPartiesRelatedByIdplayer2 = PartiePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.add(PartiePeer.IDPLAYER2, getPlayerId());
                if (!lastPartiesRelatedByIdplayer2Criteria.equals(criteria))
                {
                    collPartiesRelatedByIdplayer2 = PartiePeer.doSelect(criteria);
                }
            }
        }
        lastPartiesRelatedByIdplayer2Criteria = criteria;

        return collPartiesRelatedByIdplayer2;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getPartiesRelatedByIdplayer2(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getPartiesRelatedByIdplayer2(Connection con) throws TorqueException
    {
        if (collPartiesRelatedByIdplayer2 == null)
        {
            collPartiesRelatedByIdplayer2 = getPartiesRelatedByIdplayer2(new Criteria(10), con);
        }
        return collPartiesRelatedByIdplayer2;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Player has previously
     * been saved, it will retrieve related PartiesRelatedByIdplayer2 from storage.
     * If this Player is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getPartiesRelatedByIdplayer2(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collPartiesRelatedByIdplayer2 == null)
        {
            if (isNew())
            {
               collPartiesRelatedByIdplayer2 = new ArrayList();
            }
            else
            {
                 criteria.add(PartiePeer.IDPLAYER2, getPlayerId());
                 collPartiesRelatedByIdplayer2 = PartiePeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                 criteria.add(PartiePeer.IDPLAYER2, getPlayerId());
                 if (!lastPartiesRelatedByIdplayer2Criteria.equals(criteria))
                 {
                     collPartiesRelatedByIdplayer2 = PartiePeer.doSelect(criteria, con);
                 }
             }
         }
         lastPartiesRelatedByIdplayer2Criteria = criteria;

         return collPartiesRelatedByIdplayer2;
     }











    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Player is new, it will return
     * an empty collection; or if this Player has previously
     * been saved, it will retrieve related PartiesRelatedByIdplayer2 from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Player.
     */
    protected List getPartiesRelatedByIdplayer2JoinPlayerRelatedByIdplayer1(Criteria criteria)
        throws TorqueException
    {
        if (collPartiesRelatedByIdplayer2 == null)
        {
            if (isNew())
            {
               collPartiesRelatedByIdplayer2 = new ArrayList();
            }
            else
            {
                criteria.add(PartiePeer.IDPLAYER2, getPlayerId());
                collPartiesRelatedByIdplayer2 = PartiePeer.doSelectJoinPlayerRelatedByIdplayer1(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(PartiePeer.IDPLAYER2, getPlayerId());
            if (!lastPartiesRelatedByIdplayer2Criteria.equals(criteria))
            {
                collPartiesRelatedByIdplayer2 = PartiePeer.doSelectJoinPlayerRelatedByIdplayer1(criteria);
            }
        }
        lastPartiesRelatedByIdplayer2Criteria = criteria;

        return collPartiesRelatedByIdplayer2;
    }











        
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
            fieldNames.add("PlayerId");
            fieldNames.add("Nom");
            fieldNames.add("VaisseauId");
            fieldNames.add("Pointdaction");
            fieldNames.add("Pointdevie");
            fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by field (Java) name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
        if (name.equals("PlayerId"))
        {
            return new Integer(getPlayerId());
        }
        if (name.equals("Nom"))
        {
            return getNom();
        }
        if (name.equals("VaisseauId"))
        {
            return new Integer(getVaisseauId());
        }
        if (name.equals("Pointdaction"))
        {
            return new Integer(getPointdaction());
        }
        if (name.equals("Pointdevie"))
        {
            return new Integer(getPointdevie());
        }
        return null;
    }

    /**
     * Set a field in the object by field (Java) name.
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByName(String name, Object value )
        throws TorqueException, IllegalArgumentException
    {
        if (name.equals("PlayerId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setPlayerId(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Nom"))
        {
            // Object fields can be null
            if (value != null && ! String.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setNom((String) value);
            return true;
        }
        if (name.equals("VaisseauId"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setVaisseauId(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Pointdaction"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setPointdaction(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Pointdevie"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setPointdevie(((Integer) value).intValue());
            return true;
        }
        return false;
    }

    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
        if (name.equals(PlayerPeer.PLAYER_ID))
        {
            return new Integer(getPlayerId());
        }
        if (name.equals(PlayerPeer.NOM))
        {
            return getNom();
        }
        if (name.equals(PlayerPeer.VAISSEAU_ID))
        {
            return new Integer(getVaisseauId());
        }
        if (name.equals(PlayerPeer.POINTDACTION))
        {
            return new Integer(getPointdaction());
        }
        if (name.equals(PlayerPeer.POINTDEVIE))
        {
            return new Integer(getPointdevie());
        }
        return null;
    }

    /**
     * Set field values by Peer Field Name
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPeerName(String name, Object value)
        throws TorqueException, IllegalArgumentException
    {
      if (PlayerPeer.PLAYER_ID.equals(name))
        {
            return setByName("PlayerId", value);
        }
      if (PlayerPeer.NOM.equals(name))
        {
            return setByName("Nom", value);
        }
      if (PlayerPeer.VAISSEAU_ID.equals(name))
        {
            return setByName("VaisseauId", value);
        }
      if (PlayerPeer.POINTDACTION.equals(name))
        {
            return setByName("Pointdaction", value);
        }
      if (PlayerPeer.POINTDEVIE.equals(name))
        {
            return setByName("Pointdevie", value);
        }
        return false;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
        if (pos == 0)
        {
            return new Integer(getPlayerId());
        }
        if (pos == 1)
        {
            return getNom();
        }
        if (pos == 2)
        {
            return new Integer(getVaisseauId());
        }
        if (pos == 3)
        {
            return new Integer(getPointdaction());
        }
        if (pos == 4)
        {
            return new Integer(getPointdevie());
        }
        return null;
    }

    /**
     * Set field values by its position (zero based) in the XML schema.
     *
     * @param position The field position
     * @param value field value
     * @return True if value was set, false if not (invalid position / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPosition(int position, Object value)
        throws TorqueException, IllegalArgumentException
    {
    if (position == 0)
        {
            return setByName("PlayerId", value);
        }
    if (position == 1)
        {
            return setByName("Nom", value);
        }
    if (position == 2)
        {
            return setByName("VaisseauId", value);
        }
    if (position == 3)
        {
            return setByName("Pointdaction", value);
        }
    if (position == 4)
        {
            return setByName("Pointdevie", value);
        }
        return false;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
        save(PlayerPeer.DATABASE_NAME);
    }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
     *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
        try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
    }

    /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
        if (!alreadyInSave)
        {
            alreadyInSave = true;



            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    PlayerPeer.doInsert((Player) this, con);
                    setNew(false);
                }
                else
                {
                    PlayerPeer.doUpdate((Player) this, con);
                }
            }


            if (collPartiesRelatedByIdplayer1 != null)
            {
                for (int i = 0; i < collPartiesRelatedByIdplayer1.size(); i++)
                {
                    ((Partie) collPartiesRelatedByIdplayer1.get(i)).save(con);
                }
            }

            if (collPartiesRelatedByIdplayer2 != null)
            {
                for (int i = 0; i < collPartiesRelatedByIdplayer2.size(); i++)
                {
                    ((Partie) collPartiesRelatedByIdplayer2.get(i)).save(con);
                }
            }
            alreadyInSave = false;
        }
    }


    /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param key playerId ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
        setPlayerId(((NumberKey) key).intValue());
    }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
        setPlayerId(Integer.parseInt(key));
    }


    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
        return SimpleKey.keyFor(getPlayerId());
    }
 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     */
    public Player copy() throws TorqueException
    {
        return copy(true);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     *
     * @param con the database connection to read associated objects.
     */
    public Player copy(Connection con) throws TorqueException
    {
        return copy(true, con);
    }

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     */
    public Player copy(boolean deepcopy) throws TorqueException
    {
        return copyInto(new Player(), deepcopy);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     * @param con the database connection to read associated objects.
     */
    public Player copy(boolean deepcopy, Connection con) throws TorqueException
    {
        return copyInto(new Player(), deepcopy, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     */
    protected Player copyInto(Player copyObj) throws TorqueException
    {
        return copyInto(copyObj, true);
    }

  
    /**
     * Fills the copyObj with the contents of this object using connection.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param con the database connection to read associated objects.
     */
    protected Player copyInto(Player copyObj, Connection con) throws TorqueException
    {
        return copyInto(copyObj, true, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     */
    protected Player copyInto(Player copyObj, boolean deepcopy) throws TorqueException
    {
        copyObj.setPlayerId(playerId);
        copyObj.setNom(nom);
        copyObj.setVaisseauId(vaisseauId);
        copyObj.setPointdaction(pointdaction);
        copyObj.setPointdevie(pointdevie);

        copyObj.setPlayerId( 0);

        if (deepcopy)
        {


        List vPartiesRelatedByIdplayer1 = getPartiesRelatedByIdplayer1();
        if (vPartiesRelatedByIdplayer1 != null)
        {
            for (int i = 0; i < vPartiesRelatedByIdplayer1.size(); i++)
            {
                Partie obj = (Partie) vPartiesRelatedByIdplayer1.get(i);
                copyObj.addPartieRelatedByIdplayer1(obj.copy());
            }
        }
        else
        {
            copyObj.collPartiesRelatedByIdplayer1 = null;
        }


        List vPartiesRelatedByIdplayer2 = getPartiesRelatedByIdplayer2();
        if (vPartiesRelatedByIdplayer2 != null)
        {
            for (int i = 0; i < vPartiesRelatedByIdplayer2.size(); i++)
            {
                Partie obj = (Partie) vPartiesRelatedByIdplayer2.get(i);
                copyObj.addPartieRelatedByIdplayer2(obj.copy());
            }
        }
        else
        {
            copyObj.collPartiesRelatedByIdplayer2 = null;
        }
        }
        return copyObj;
    }
        
    
    /**
     * Fills the copyObj with the contents of this object using connection.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     * @param con the database connection to read associated objects.
     */
    protected Player copyInto(Player copyObj, boolean deepcopy, Connection con) throws TorqueException
    {
        copyObj.setPlayerId(playerId);
        copyObj.setNom(nom);
        copyObj.setVaisseauId(vaisseauId);
        copyObj.setPointdaction(pointdaction);
        copyObj.setPointdevie(pointdevie);

        copyObj.setPlayerId( 0);

        if (deepcopy)
        {


        List vPartiesRelatedByIdplayer1 = getPartiesRelatedByIdplayer1(con);
        if (vPartiesRelatedByIdplayer1 != null)
        {
            for (int i = 0; i < vPartiesRelatedByIdplayer1.size(); i++)
            {
                Partie obj = (Partie) vPartiesRelatedByIdplayer1.get(i);
                copyObj.addPartieRelatedByIdplayer1(obj.copy(con), con);
            }
        }
        else
        {
            copyObj.collPartiesRelatedByIdplayer1 = null;
        }


        List vPartiesRelatedByIdplayer2 = getPartiesRelatedByIdplayer2(con);
        if (vPartiesRelatedByIdplayer2 != null)
        {
            for (int i = 0; i < vPartiesRelatedByIdplayer2.size(); i++)
            {
                Partie obj = (Partie) vPartiesRelatedByIdplayer2.get(i);
                copyObj.addPartieRelatedByIdplayer2(obj.copy(con), con);
            }
        }
        else
        {
            copyObj.collPartiesRelatedByIdplayer2 = null;
        }
        }
        return copyObj;
    }
    
    

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public PlayerPeer getPeer()
    {
        return peer;
    }

    /**
     * Retrieves the TableMap object related to this Table data without
     * compiler warnings of using getPeer().getTableMap().
     *
     * @return The associated TableMap object.
     */
    public TableMap getTableMap() throws TorqueException
    {
        return PlayerPeer.getTableMap();
    }


    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Player:\n");
        str.append("PlayerId = ")
           .append(getPlayerId())
           .append("\n");
        str.append("Nom = ")
           .append(getNom())
           .append("\n");
        str.append("VaisseauId = ")
           .append(getVaisseauId())
           .append("\n");
        str.append("Pointdaction = ")
           .append(getPointdaction())
           .append("\n");
        str.append("Pointdevie = ")
           .append(getPointdevie())
           .append("\n");
        return(str.toString());
    }
}
